<?php

/**
 * character actions.
 *
 * @package    wte
 * @subpackage character
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class characterActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
  		$form = new CharacterTemplateForm();
		$characters = Doctrine::getTable('CharacterTemplate')->findAll();
		
		// On passe à la vue
		$this->form = $form;
		$this->characters = $characters;
  }

  public function executeCreate(sfWebRequest $request)
  {
	$form = new CharacterTemplateForm();
	$form->bind($request->getParameter('character_template'));
	
	$form->save();
	if($request->isXmlHttpRequest())
	{
		$list = Doctrine::getTable('CharacterTemplate')->findAll();
		return $this->renderText($this->getPartial('characterList',array('list' => $list)));
	}

  }

  public function executeEdit(sfWebRequest $request)
  {
	
	$character =  $this->getRoute()->getObject();
	$form = new CharacterTemplateForm($character);
	$this->character = $character;	

	if($request->isMethod('post'))
	{
		$form->bind($request->getParameter('character_template'));
		$form->save();
	}	
	
	$this->form = $form;
  }

  public function executeDelete(sfWebRequest $request)
  {
	$this->getRoute()->getObject()->delete();
	if($request->isXmlHttpRequest())
	{
		$list = Doctrine::getTable('CharacterTemplate')->findAll();
		return $this->renderText($this->getPartial('characterList',array('list' => $list)));
	}	
	
	$this->forward('character','index');
  }
















}
